package com.huawei.appgallery.packagemanager.api.bean;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import com.huawei.appgallery.datastorage.database.EnableDatabase;
import com.huawei.appgallery.datastorage.database.RecordBean;
import java.io.File;
import java.io.IOException;
import o.cnu;

public class ProfileTask extends RecordBean {
    @EnableDatabase
    public String packageName;
    @EnableDatabase
    public String profileName;
    @EnableDatabase
    public String profilePath;
    @EnableDatabase
    public String profileUrl;
    @EnableDatabase
    public String sha256;
    @EnableDatabase
    public int status = 0;
    @EnableDatabase
    public int versionCode;
    private String ˏ = "";

    public String ˊ() {
        return "ProfileTask";
    }

    public File ॱ(Context context) {
        File createTempFile;
        File file = new File(new File(context.getFilesDir(), "ProfileCache"), "tmp");
        ˋ(file);
        if (TextUtils.isEmpty(this.profileUrl)) {
            this.profileName = this.packageName + this.versionCode;
        } else {
            this.profileName = Uri.parse(this.profileUrl).getLastPathSegment();
        }
        try {
            createTempFile = File.createTempFile(this.profileName, null, file);
            this.profilePath = createTempFile.getCanonicalPath();
            return createTempFile;
        } catch (IOException e) {
            cnu.ˏ.ˊ("ProfileTask", "createTempFile failed.");
            this.profilePath = file.getAbsolutePath() + File.separator + this.profileName + ".tmp";
            createTempFile = new File(this.profilePath);
            try {
                if (!createTempFile.delete()) {
                    cnu.ˏ.ˊ("ProfileTask", "delete failed");
                }
                if (createTempFile.createNewFile()) {
                    return createTempFile;
                }
                cnu.ˏ.ˊ("ProfileTask", "createNewFile failed");
                return createTempFile;
            } catch (IOException e2) {
                cnu.ˏ.ˊ("ProfileTask", "createNewFile failed.");
                return createTempFile;
            }
        }
    }

    protected void ˋ(File file) {
        if (!file.exists() && !file.mkdirs()) {
            cnu.ˏ.ˋ("ProfileTask", "mkdir failed");
        }
    }

    public File ˋ(Context context) {
        File file = new File(context.getFilesDir(), "ProfileCache");
        if (!(file.exists() || file.mkdirs())) {
            cnu.ˏ.ˊ("ProfileTask", "make dir failed");
        }
        File file2 = new File(file, this.profileName + ".dm");
        this.profilePath = file2.getAbsolutePath();
        return file2;
    }

    public String ˋ() {
        return this.ˏ;
    }

    public void ˏ(String str) {
        this.ˏ = str;
    }
}
